<script setup lang='ts'>
import type { OptionsType, PlusColumn } from 'plus-pro-components'
import type { VxeGridProps } from 'vxe-table'

import { SearchForm, SearchTable } from '@fl/components'
import { cloneDeep } from 'lodash-es'

defineOptions({
    // eslint-disable-next-line vue/component-definition-name-casing
    name: '/pages/counselor/apply-for-enter',
})

const router = useRouter()

const initialState = {
    counselorName: '',
    houseName: '',
}
const state = ref(cloneDeep(initialState))

const searchConditions = ref(cloneDeep(initialState))
const tablePage = reactive({
    currentPage: 1,
    pageSize: 10,
    total: 0,
})
const _getCounselorPageParams = computed(() => ({
    ...searchConditions.value,
    page: tablePage.currentPage,
    size: tablePage.pageSize,
}))

// #region Form
const isFormLoading = computed(() => false)

const columns: PlusColumn[] = [
    {
        colProps: {
            span: 6,
        },
        label: '置业顾问名称',
        prop: 'counselorName',
        valueType: 'copy',
    },
    {
        colProps: {
            span: 6,
        },
        label: '楼盘名称',
        prop: 'houseName',
        valueType: 'copy',
    },
]

function submit() {
    searchConditions.value = cloneDeep(state.value)
    resetTablePage()
}

function reset() {
    state.value = cloneDeep(initialState)
    searchConditions.value = cloneDeep(initialState)
    resetTablePage()
}

function resetTablePage() {
    tablePage.currentPage = 1
    tablePage.pageSize = 10
}
// #endregion

// #region Table
const isTableLoading = computed(() => false)
const tableData = ref<any[]>([
    {
        applyStatus: '已通过',
        applyTime: '2024-09-10 23:59:59',
        avatar: '',
        contactTime: '2024-09-13 23:59:59',
        id: '0101',
        name: '张三',
        phone: '1888888888',
        relativeHouse: '武汉城建·汉江云宸',
    },
])

const gridOptions = reactive<VxeGridProps>({
    columns: [
        { field: 'id', title: '申请ID' },
        { field: 'avatar', slots: { default: 'avatar' }, title: '头像' },
        { field: 'name', title: '名称' },
        { field: 'phone', title: '手机号' },
        { field: 'relativeHouse', title: '关联楼盘' },
        { field: 'applyTime', title: '申请时间' },
        { field: 'applyStatus', title: '申请状态' },
        { field: 'operation', slots: { default: 'operation' }, title: '操作' },
    ],
})
// #endregion

// #region UI Listener
function onCheckDetailBtnClick(row: any) {
    router.push(
        {
            path: '/trade-center/counselor/counselor-detail',
            query: {
                id: row.id,
            },
        },
    )
}

function onPassBtnClick(row: any) {

}

function onRejectBtnClick(row: any) {

}
// #endregion

// watchEffect(() => {
//     tableData.value = cloneDeep(productPageData.value)
//     tablePage.total = productTotal.value
// })
// #endregion
</script>

<template>
    <el-card mb-20
             shadow="never"
    >
        <el-skeleton v-if="isFormLoading"
                     animated
        />

        <SearchForm v-else
                    v-model="state"
                    :columns="columns"
                    submit-text="查询"
                    :row-props="{ gutter: 40 }"
                    @submit="submit"
                    @reset="reset"
        />
    </el-card>

    <el-card shadow="never">
        <SearchTable v-bind="gridOptions"
                     v-model:pager="tablePage"
                     :loading="isTableLoading"
                     :data="tableData"
        >
            <template #avatar="{ row }">
                <img src="https://tse1-mm.cn.bing.net/th/id/OIP-C.p9N4LqKEfaJ2AewVtiYTiAAAAA?rs=1&pid=ImgDetMain"
                     alt=""
                     width="40"
                     height="40"
                     class="m-auto"
                >
            </template>

            <template #operation="{ row }">
                <el-button text
                           class="!p-4 !text-#409EFF"
                           @click="onCheckDetailBtnClick(row)"
                >
                    查看
                </el-button>

                <el-button text
                           class="!p-4 !text-#409EFF"
                           @click="onPassBtnClick(row)"
                >
                    通过
                </el-button>

                <el-button text
                           class="!p-4 !text-#409EFF"
                           @click="onRejectBtnClick(row)"
                >
                    拒绝
                </el-button>
            </template>
        </SearchTable>
    </el-card>
</template>

<style lang="scss" scoped>

</style>
